package org.example;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class 第三十五章_多线程编程 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //实现Runnable
        P1 p1 = new P1();
        new Thread(p1).start();

        //继承Thread
        P2 p2 = new P2();
        p2.start();

        //通过 Callable 和 Future 创建线程
        P3 p3 = new P3();
        FutureTask<String> ft = new FutureTask<>(p3);
        new Thread(ft).start();
        System.out.println(ft.get());
    }

    //实现Runnable
    static class P1 implements Runnable{

        @Override
        public void run() {
            System.out.println("123456");
        }
    }

    //继承Thread
    static class P2 extends Thread{
        @Override
        public void run() {
            System.out.println("789456");
        }
    }

    //通过 Callable 和 Future 创建线程
    static class P3 implements Callable<String> {
        @Override
        public String call() throws Exception {
            return "11111111";
        }
    }
}
